

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class CheckCookie
 * 쿠키를 읽어 들이는 예제임 
 */
public class CheckCookie extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		Cookie[] cookies = request.getCookies();

		
		for (int i = 0 ; i < cookies.length ; i++){
			Cookie cookie = cookies[i]; 
			if(cookie.getName().equals("username")){
				String userName = cookie.getValue();
				out.println("Hello : " + userName);
			}
		}
		
	}

}
